package com.basker.pisces.orm.statement;

import com.basker.pisces.core.meta.IDataField;
import com.basker.pisces.orm.data.meta.FieldMeta;

public class PKFieldObject extends FieldObject {
    private Object dataObject;

    public PKFieldObject(FieldMeta pkFieldMeta, Object dataObject) {
        super(pkFieldMeta, null);
        this.dataObject = dataObject;
        this.value = this.getValue();
    }

    @Override
    public Object getValue() {
        IDataField dataField = this.getDataField();
        if (dataField != null) {
            return dataField.getValue(this.dataObject);
        }

        return this.value;
    }

    public void setPkValue(Object pkValue) {
        IDataField dataField = this.getDataField();
        if (dataField != null) {
            dataField.setValue(this.dataObject, pkValue);
        }

        this.value = pkValue;
    }
}
